<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/11/10
 * Time: 10:41
 */

namespace app\flower\controller;
use cmf\controller\AdminBaseController;
use app\flower\model\FlowerOrderchangeModel;
class AdminOrderchangeController extends AdminBaseController
{
    public function index(){
        $model = new FlowerOrderchangeModel();
        $result  = $model->where('deltime','')->order('dottime','desc')->paginate(8);
        $page = $result->render();
        $this->assign('result',$result);
        $this->assign('page',$page);
        return $this->fetch('orderchange');
    }

    /**
     * 信息收缩
     */
    public function searchorder(){
        $ordersql = new FlowerOrderchangeModel();
        $start_time = input('start_time');//开始时间
        $end_time = input('end_time');//结束时间
        if($start_time!=null&&$end_time!=null){
            $ordersql = $ordersql->where('dottime','>=',strtotime($start_time))->where('dottime','<=',strtotime($end_time));
        }else if($start_time!=null&&$end_time==null){
            $this->error('请选择结束时间');
        }else if($start_time==null&&$end_time!=null){
            $this->error('请选择开始时间');
        }
        $keyword = input('keyword');//关键词
        if($keyword!=null){
            $ordersql = $ordersql->where('orderid|phone','like','%'.trim($keyword).'%');
        }
        $result = $ordersql->where('deltime','')->order('dottime','desc')->paginate(8);
        $page = $result->render();
        $this->assign('result',$result);
        $this->assign('page',$page);
        return $this->fetch('orderchange');
    }

    /**
     * 数据删除
     */
    public function delete(){
        $model = new FlowerOrderchangeModel();
        $param = $this->request->param();
        //删除单个
        if(isset($param['id'])){
            $id = $this->request->param('id');
            $result = $model->where('id',$id)->update(array('deltime'=>time()));
            if($result>0){
                $this->success('删除成功');
            }else{
                $this->success('删除失败');
            }
        }
        //批量删除
        if(isset($param['ids'])){
            // print_r($param);exit;
            $ids = $this->request->param('ids/a');//转成数组
            $result = $model->where(array('id'=>array('in',$ids)))->update(array('deltime'=>time()));
            if($result>0){
                $this->success('删除成功');
            }else{
                $this->success('删除失败');
            }
        }

    }

}